<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>财务流水</title>
</head>
<body>
<style>
    .m15 .form-inline .form-group{
        margin-right: 15px;
    }
</style>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span>
    财务管理
    <span class="c-gray en">&gt;</span>
    退款管理
</nav>
<div class="page-container">
    <div class="row mt-20">
        <div id="platformFinancialFormToolBars">
            <form class="form-inline" id="platformFinancialForms">
                <div class="form-group">
                    <label class="control-label" title="">
                        订单类型：
                    </label>
                    <select class="form-control" name="orderType">
                        <option value="">请选择</option>
                        <option value="1">洗车</option>
                        <option value="2">美容</option>
                        <option value="3">保养</option>
                        <option value="4">维修</option>
                        <option value="5">卡券</option>
                    </select>
                </div>
                <div class="form-group">
                    <label class="control-label" title="">
                        支付方式：
                    </label>
                    <select class="form-control" name="payType">
                        <option value="">请选择</option>
                        <option value="1">现金</option>
                        <option value="2">微信</option>
                        <option value="3">支付宝</option>
                    </select>
                    <!--<input  type="text" value="" class="form-control">-->
                </div>
                <div class="form-group">
                    <label class="control-label">商户名称：</label>
                    <select class="form-control" name="bizId" id="platform-finances-bizId">
                        <option value="">请选择</option>
                    </select>
                </div>
                <div class="form-group">
                    <label class="control-label" title="">
                        开始时间：
                    </label>
                    <input id="platformFinancialTimeStarts" name="addTimeStart" type="text" onfocus="WdatePicker()"
                           readonly="readonly" class="form-control Wdate" style="width:150px;">
                </div>
                <div class="form-group">
                    <label class="control-label" title="">
                        结束时间：
                    </label>
                    <input id="platformFinancialTimeEnds" name="addTimeEnd" type="text" onfocus="WdatePicker()"
                           readonly="readonly" class="form-control Wdate" style="width:150px;">
                </div>
                <span onclick="platformFinanceFinancialFlows.searchAction();" class="btn btn-default">查询 <i class="glyphicon glyphicon-search"></i></span>
            </form>
        </div>
        <div class="col-xs-12">
            <table id="platform-tableFinancialFlows" class="table table-bordered table-striped text-center">
            </table>
        </div>
    </div>
</div>
    <!--******************退款模态框****************-->
<div class="modal fade refund-modal" tabindex="-1" role="dialog" id="refunds-modal">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title adOredit">退款</h4>
            </div>
            <div class="modal-body">
                <form action="" method="post" class="form form-horizontal" id="autoServicePackages-form">
                    <input style="display: none;" id="refunds-shopId" name="shopId"/>
                    <input style="display: none;" id="refunds-bizShopPackage" name="bizShopPackage"/>

                    <!-- 隐藏域，传递 -->
                    <input type="text" class="form-control" name="transactionId" id="transactionIds" style="display: none;">
                    <input type="text" class="form-control" name="totalFee" id="totalFees" style="display: none;">

                    <div class="form-group">
                        <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>退款理由：</label>
                        <div class="formControls col-xs-4 col-sm-4">
                            <input type="text" class="form-control" value="" placeholder="请输入退款理由" id="refundDesc" name="refundDesc">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button onclick="platformFinanceFinancialFlows.refundBtnSure()" type="button" class="btn btn-primary">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>

        </div>
    </div>
</div>
<script>
    //退款管理
    var platformFinanceFinancialFlows = {
        init: function () {
            //加载门店名称
            $.ajax({
                type: "GET",
                url: "biz/getAllBizNameExistShop",
                dataType: "json",
                success: function (data) {
                    for(var i = 0;i<data.length;i++){
                        $("#platform-finances-bizId").append("<option value='"+data[i].id+"'>"+data[i].text+"</option>");
                    }
                },
                error: function () {
                    alert("error");
                }
            });

            let _this = this;
            //设置页面初次加载时，时间控件所显示的时间
            var addTimeStart = _this.time(-1);
            var addTimeEnd = _this.time(0);
            $("#platformFinancialTimeStarts").val(addTimeStart);
            $("#platformFinancialTimeEnds").val(addTimeEnd);

            //商户财务流水展示所有
            $('#platform-tableFinancialFlows').bootstrapTable({
                url: 'cust/getAllOrderItem?addTimeStart=' + addTimeStart + "&addTimeEnd=" + addTimeEnd,     //请求后台的URL（*）
                method: 'get',
                toolbar : '#platformFinancialFormToolBars',
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortable: false,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                //search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                // height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                showToggle: true,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                columns: [
                    {
                        checkbox: true
                    }, {
                        field: 'orderId',
                        title: '订单号'
                    }, {
                        field: 'orderType',
                        title: '订单类型',
                        formatter:function(value,row,index){
                            if(value == '1'){
                                return '洗车';
                            }else if(value == '2') {
                                return '美容';
                            }else if(value == '3') {
                                return '保养';
                            }else if(value == '4') {
                                return '维修';
                            }else if(value == '5') {
                                return '卡券';
                            }
                        }
                    }, {
                        field: 'bizName',
                        title: '商户名称'
                    }, {
                        field: 'payType',
                        title: '支付方式',
                        formatter:function(value,row,index){
                            if(value == '1'){
                                return '现金';
                            }else if(value == '2') {
                                return '微信';
                            }else if(value == '3') {
                                return '支付宝';
                            }else {
                                return '未支付';
                            }
                        }
                    }, {
                        field: 'price',
                        title: '原价',
                        formatter:function(value,row,index){
                            if(value != null){
                                return value/100;
                            }
                        }
                    }, {
                        field: 'debateAmount',
                        title: '优惠价',
                        formatter:function(value,row,index){
                            if(value != null){
                                return value/100;
                            }
                        }
                    },  {
                        field: 'totalFee',
                        title: '支付金额',
                        formatter:function(value,row,index){
                            if(value != null){
                                return value/100;
                            }
                        }
                    }, {
                        field: 'payState',
                        title: '支付状态',
                        formatter:function(value,row,index){
                            if(value == '12'){
                                return '支付中';
                            }else if (value == '11'){
                                return '已支付';
                            }else if (value == '14'){
                                return '支付失败';
                            }else if (value == '22'){
                                return '退款中';
                            }else if (value == '21'){
                                return '已退款';
                            }else if (value == '24'){
                                return '退款失败';
                            }else {
                                return '-';
                            }
                        }
                    }, {
                        field: 'tradeNo',
                        title: '微信支付单号'
                    }, {
                        field: 'addTime',
                        title: '创建时间'
                    }
                    , {
                        title: '操作',
                        formatter : function (value, row,index) {
                            return `
                                    ${row.payType == 2 && (row.payState == 11 || row.payState == 24) ?  `<a class="btn btn-danger btn-sm"  data-toggle="modal"
                                     data-target=".refund-modal" onclick="platformFinanceFinancialFlows.refund('${row.tradeNo}','${row.totalFee}')"  >退款 </a>` : '' } `
                        }
                    }
                ]
            });
        },
        //查询
        searchAction: function () {
            $.ajax({
                type: "get",
                url: "cust/getAllOrderItem",
                data: $("#platformFinancialForms").serialize(),
                dataType: "json",
                success: function (json) {
                    $("#platform-tableFinancialFlows").bootstrapTable('load', json);
                },
                error: function () {
                    alert("error");
                }
            });
        },
        //退款
        searchActions: function () {
            $.ajax({
                type: "get",
                url: "cust/refunds",
                data: $("#platformFinancialForms").serialize(),
                dataType: "json",
                success: function (json) {
                    alert("success!");
                },
                error: function () {
                    alert("error");
                }
            });
        },
        //退款
        refund:function(transactionId,totalFee){
            //点击table表格中的退款按钮，给隐藏域赋值
            $("#transactionIds").val(transactionId);
            $("#totalFees").val(totalFee);
        },
        //确定退款
        refundBtnSure:function(){
            var transactionId = $("#transactionIds").val();
            var totalFee = $("#totalFees").val();
            var refundDesc = $("#refundDesc").val();

            $.ajax({
                type: "get",
                url: "cust/refunds",
                data: { transactionId: transactionId, totalFee: totalFee,refundFee: totalFee,refundDesc: refundDesc },
                dataType: "json",
                success: function (json) {
                    if(json.state == true){
                        //刷新
                        $("#platform-tableFinancialFlows").bootstrapTable("refresh");

                        alert("退款申请，已提交！");
                    }else {
                        alert(json.data.message);
                    }
                    //隐藏
                    $("#refunds-modal").modal('hide');
                },
                error: function () {
                    alert("error");
                }
            });

        },
        //获取时间的方法
        time: function (index) {
            var today = new Date();
            today.setMonth(today.getMonth() + index);
            var h = today.getFullYear();
            var m = today.getMonth() + 1;
            var d = today.getDate();
            m = m < 10 ? "0" + m : m;
            d = d < 10 ? "0" + d : d;
            return h + "-" + m + "-" + d;
        }
    };

    platformFinanceFinancialFlows.init();
</script>
</body>
</html>